{% extends "base.html" %}
{% load utils %}

{% block content %}
<div id="content-header">
<h2>支付</h2>
<div class="top-tools">
</div>
<div class="clear"></div>
</div>

<form method="post" action=".">
	{% render_form form %}
	{% for mem in form.members %}<input type="hidden" name="member_ids" value="{{ mem.id }}" />{% endfor %}
	<ul class="dist_mode" id="dm_percent" style="{% ifequal form.data.dist_mode 'P' %}{%else%}display:none{% endifequal %}">
		{% for mem in form.members %}
		<input type="hidden" name="dm_number_member" value="{{ mem.id }}" />
		<li><label for="dm_percent_{{ mem.id }}">{{ mem.name }}</label>
		<input type="text" name="dm_percent_{{ mem.id }}" id="dm_percent_{{ mem.id }}" value="{{ form.data|dm_percent:mem }}" /> %
		</li>
		{% endfor %}
	</ul>
	<ul class="dist_mode" id="dm_number" style="{%ifequal form.data.dist_mode 'N' %}{%else%}display:none{%endifequal%}">
		{% for mem in form.members %}
		<input type="hidden" name="dm_number_member" value="{{ mem.id }}" />
		<li><label for="dm_number_{{ mem.id }}">{{ mem.name }}</label>
		<input type="text" name="dm_number_{{ mem.id }}" id="dm_number_{{ mem.id }}" value="{{ form.data|dm_number:mem }}" /> 元
		</li>
		{% endfor %}
	</ul>

	<div class="form-buttons">
		<button class="button" type="submit">保存</button>
		<a href="/sa/{{ account.id }}/">取消</a>
	</div>
</form>
{% endblock %}

{% block embedded_javascript %}
(function($) {
	$("input[name=dist_mode]").change(function() {
		var value = $('input[name=dist_mode]:checked').val();
		if (value == "P") {
			$("#dm_percent").show();
			$("#dm_number").hide();
		} else if (value == "N") {
			$("#dm_percent").hide();
			$("#dm_number").show();
		} else {
			$("#dm_percent").hide();
			$("#dm_number").hide();
		}
	}).filter(':first').trigger('change');
})(jQuery);
{% endblock %}
